﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NavLine.Aircraft
{
	public partial class AC_Controller
	{
		public bool NavigatingHeading = false;
		double TargetHead;
		double TargetBank = 0;
		public void MaintainHeading(double hdg)
		{
			ResetControl();
			if (hdg > 360)
				hdg -= 360;
			if (hdg < 0)
				hdg += 360;
			TargetHead = hdg;
			NavigatingHeading = true;
		}
		void ProcessHeading(double dt)
		{
			if (NavigatingHeading)
			{
				double delta = TargetHead - aircraft.heading;
				if (delta < -180)
					delta += 360;
				if (delta > 180)
					delta -= 360;

				delta = Math.Max(-10, Math.Min(10, delta)) / 10;
				//delta = delta - BankControll.Value / 10;

				BankControll.Set(delta);
			}
			else
				BankControll.Set(0);
			BankControll.SetTime(aircraft.config.BankT);
			BankControll.Process(dt);
			aircraft.bank = BankControll.Value;
		}
	}
}